<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/common.jsp"%>
<title>积分充值</title>
</head>
<body>
		<%@ include file="../common/header.jsp"%>
		<div class="container">
			<div class="row">
				<div class="col-md-9">
					<div class="panel panel-default">
						<div class="panel-heading">
							你的当前积分:<strong><fmt:formatNumber type="number" value="${pointAccount.currentValue}" pattern="0.00" maxFractionDigits="2"/></strong>
						</div>
						<div class="panel-body">
							<c:if test="${pointAccount.hasPassword eq 0}">
								<p>你还未设置支付密码，请点此先去<a href="${ctx}/memberCenter/alterPayPassword">设置支付密码</a></p>
							</c:if>
							<c:if test="${pointAccount.hasPassword eq 1}">
								<form>
									<div class="form-group">
										<label for="cardNo">卡号</label>
										 <input type="text" class="form-control" id="cardNo" >
									</div>
									<div class="form-group">
										<label for="password">卡密</label>
										 <input type="password" class="form-control" id="password">
									</div>
									<div class="form-group">
										<label for="payPassword">支付密码</label>
										 <input type="password" class="form-control" id="payPassword">
									</div>
									<div class="form-group">
										<label for="emailCode">验证码</label>
										<div class="input-group">
											<input id="emailCode" type="text" class="form-control">
											<span class="input-group-btn">
												<button onclick="sendEmailCode()" class="btn btn-default" type="button">发送邮箱验证码</button>
											</span>
										</div>
									</div>
									<button type="button" onclick="recharge()" class="btn btn-default">充值</button>
									<span id="error_message"></span>
								</form>
							</c:if>
						</div>
					</div>
				</div>

				<div class="col-md-3 hidden-sm hidden-xs">
					<div class="panel panel-default">
						<div class="panel-heading">
							<b>积分充值指南</b>
						</div>
						<div class="panel-body">
							<p>• 获取充值卡，可<a href="https://www.taobao.com/" target="_blank">点此购买</a>。</p>
							<p>• 充值卡的面额即为要充值的积分值。</p>
							<p>• 购买商品时，本站只支持积分支付。</p>
							<p>• 1积分相当于1元，积分值可以为小数。比如，10元的商品所需积分为10；9.9元的商品，所需积分为9.9。</p>
							<p>• 在本站发布优质的文章也可以免费获得积分哦。</p>
						</div>
					</div>
				</div>
			</div>
		</div>
		<%@ include file="../common/footer.jsp"%>
	<script type="text/javascript">
		var editor = new Editor({
			element : $("#content")[0],
			status : []
		});
		editor.render();
	</script>
	<script type="text/javascript">
		function recharge() {
			var errorMsg = $("#error_message");
			var cardNo = $("#cardNo").val();
			var password = $("#password").val();
			var payPassword = $("#payPassword").val();
			var code = $("#emailCode").val();
			
			if (cardNo.length == 0) {
				errorMsg.html("卡号不能为空");
				return;
			}
			if (password.length == 0) {
				errorMsg.html("卡密不能为空");
				return;
			}
			if (payPassword.length == 0) {
				errorMsg.html("支付密码不正确");
				return;
			}
			
			$.ajax({
				type : 'POST',
				url : ctx + '/point/pointRecharge.do',
				data : {
					cardNo : cardNo,
					password : password,
					payPassword : payPassword,
					code : code
				},
				dataType : 'json',
				timeout : 30000,
				context : $('body'),
				success : function(data) {
					if (data.code == "ok") {
						window.location.reload();
					} else {
						errorMsg.html(data.msg);
					}
				},
				error : function(xhr, type) {
					errorMsg.html('提交失败!');
				}
			});
		}
	</script>
	<script type="text/javascript">
		function sendEmailCode(){
			$.ajax({
				type : 'POST',
				url : ctx + '/sendEmailCode.do',
				data : {
				},
				dataType : 'json',
				timeout : 30000,
				context : $('body'),
				success : function(data) {
					if (data.code == "ok") {
						showTip2('验证码已经发送到您的邮箱，请注意查收!');
					} else {
						showTip2(data.msg);
					}
				},
				error : function(xhr, type) {
					showTip2('提交失败!');
				}
			});
		}
	</script>
</body>
</html>